/*
* page_capture.h Notebook Firewire Capture Page Object
* Copyright (C) 2001 Charles Yates <charles.yates@pandora.be>
* Copyright (C) 2001-2007 Dan Dennedy <dan@dennedy.org>
* Copyright (C) 2007 Stéphane Brunner <stephane.brunner@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef _PAGE_CAPTURE_H
#define _PAGE_CAPTURE_H

#include "frame.h"

#include <QObject>
#include <QThread>

#include <libavc1394/avc1394.h>
#include "ieee1394io.h"

#include <vector>
using std::vector;

class IEEE1394Reader;
class QWidget;
class Displayer;

/** This class controls the firewire capture notebook page. */

typedef enum component_enum {
    EDIT_MENU = 2,
    SCENE_LIST = 32,
    VIDEO_START_OF_MOVIE = 64,
    VIDEO_START_OF_SCENE = 128,
    VIDEO_REWIND = 256,
    VIDEO_BACK = 512,
    VIDEO_PLAY = 1024,
    VIDEO_PAUSE = 2048,
    VIDEO_STOP = 4096,
    VIDEO_FORWARD = 8192,
    VIDEO_FAST_FORWARD = 16384,
    VIDEO_NEXT_SCENE = 32768,
    VIDEO_END_OF_MOVIE = 65536,
    INFO_FRAME = 131072,
    VIDEO_SHUTTLE = 262144
};

typedef enum display {
	A, B, AB, C, OUT
};

struct navigate_control
{
	int step;
	int rate;
	int subframe;
	bool active;
	bool escaped;
	bool capture_active;
};

class Input : public QObject {
	  Q_OBJECT

public:
	Input();
	~Input();
	
	Frame* getFrame();

	void init(QWidget *target, int channel);
	void CheckDevices(int port);
	
	AVPicture pixels;//[ FRAME_MAX_WIDTH * FRAME_MAX_HEIGHT * 3 ];

	IEEE1394Reader *reader;
	Displayer *screen;

	void TriggerAction();

private:
	pthread_mutex_t condition_mutex;
	pthread_cond_t condition;

	/* state info */
	long validComponents;
	int gui_state_was;

	bool driver_available;
	bool avc_enabled;
	bool check_phyid;
	bool driver_locked;

	// reader changed to pointer to delay creation of Frame
	// objects so prefs dv decoder quality is properly read
	AVC *avc;
	quadlet_t avcStatus;
};

class PageCapture : public QThread {
	  Q_OBJECT

public:
	PageCapture();
	virtual ~PageCapture();

	void addInput(QWidget *target, int channel, int port);

	void setScreen1(QWidget *target);
	void setScreen2(QWidget *target);
	void setScreen3(QWidget *target);
	
	void setABFade(float fade);
	void setCKeyYValue(char key);

	void run();
	
private:
	/* inputs */
	vector<Input*> inputs;

	/* internal channels */
	AVPicture canalAB;
	AVPicture canalOUT;

	/* mix data */
	int inputOnA;
	int inputOnB;
	int inputOnC;

	float mixAB;
	char mixOut;
	
	// AB, C or OUT 
	display onScreen3;

	Displayer *screen1;
	Displayer *screen2;
	Displayer *screen3;

	// Capture
	int lastPosition;
	int step;

private slots:
	void videoThread();
	
};

#endif
